package com.kotlin.lib

class Person constructor(name: String) {
    private val userName: String = name.toUpperCase();
    private var address: String
    private var age: Int
    var isMale = false

    constructor(name: String, age: Int = 21) : this(name) {
        this.age = age
    }

    constructor(name: String, age: Int, address: String) : this(name, age) {
        this.address = address
    }

    init {
        println("Person[name=$name]")
        age = 20
        address = "BeiJin"
    }

    override fun toString(): String {
        return "userName=$userName, age=$age, address=$address"

    }
}

open class Parent constructor(name: String)

//父类型有primary构造方法，值类型却没有。需要在secondary构造方法调用super或者通过调用this其它构造方法初始化父类型
class Child : Parent {
    constructor(name: String) : super(name) {
        println("$name")
    }
}

//默认参数
class P constructor(
    private val name: String,
    private val address: String,
    private val age: Int = 15
) {

    fun printInfo() = print("name:$name, address:$address, age:$age")
}

fun main() {
    var person: Person? = null
    println("${person?.isMale},${person?.isMale == true},${person?.isMale == false}")

    val p = Person("zhangSan", 30, "ShangHai")
    println(p.toString())
    val p1 = P("lisi", "beiJin", 12)
    p1.printInfo()
}